// src/api/index.js
import axios from 'axios'
const API_BASE_URL = '/api' // Vite proxy 会处理这个路径

export const fetchSensorData = async (sensorId) => {
  const response = await fetch(`${API_BASE_URL}/sensor-data?sensorId=${sensorId}`)
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`)
  }
  return await response.json()
}

export const fetchEvaluationData = async (device) => {
  const response = await fetch(`${API_BASE_URL}/evaluation-data?device=${device}`)
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`)
  }
  return await response.json()
}

//故障溯源
export function getFaultTracingGraph(eventId) {
  return axios.get('/graph/graphDataByEventId', {
    params: { eventId }
  })
}